package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.module.contract.ModifyOpinionContract;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by pc on 2018/7/18.
 */

public class ModifyOpinionModel implements ModifyOpinionContract.Model {


    @Override
    public Disposable modify(final RequestCallback<Code> callback, Map<String,String> param) {
        return App.getComponent().getAPIService().addNewOpinion(param).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new OfficeSubscriber<Code>(callback){
            @Override
            public void onNext(Code o) {
                if(o.isSucceed()){
                    callback.requestSuccess(o);
                }else{
                    callback.requestError(o.getMessage());
                }
            }
        });
    }


}
